<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        // 数字范围在1-3999
        var romanToInt = function(s) {
            const romaArrs = new Map()
            romaArrs.set('I',1)
            romaArrs.set('V',5)
            romaArrs.set('X',10)
            romaArrs.set('L',50)
            romaArrs.set('C',100)
            romaArrs.set('D',500)
            romaArrs.set('M',1000)
            let sSum = 0, len = s.length
            for(let i = 0; i < len; i++) {
                let value = romaArrs.get(s[i])
                if(i<len-1 && value<romaArrs.get(s[i+1])){
                    sSum -= value
                    continue
                }
                sSum += value
            }
            return sSum
        }
        
        console.log(romanToInt('IV'));
    </script>
</body>
</html>